﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Notoric.Model.Validation
{
    /// <summary>
    /// Implements a rule that constraints the type of the value
    /// to be a subtype of <typeparamref name="T"/> and the value
    /// not to be <see langword="null"/>.
    /// </summary>
    /// <typeparam name="T">Type of the property value</typeparam>
    public class NotNullRule<T> : Rule
    {
        #region Constructors

        /// <summary>
        /// Creates a new <see cref="NotNullRule{T}"/> instance.
        /// </summary>
        /// <param name="propertyName">
        /// <para>
        /// Type: <see cref="System.String"/>
        /// </para>
        /// <para>
        /// Name of the property controlled by this rule
        /// </para>
        /// </param>
        /// <param name="description">
        /// <para>
        /// Type: <see cref="System.String"/>
        /// </para>
        /// <para>
        /// Description of this rule
        /// </para>
        /// </param>
        /// <param name="descriptionKey">
        /// <para>
        /// Type: <see cref="System.String"/>
        /// </para>
        /// <para>
        /// Dictionary key of the rule description
        /// </para>
        /// </param>
        public NotNullRule(string propertyName, string description, string descriptionKey)
            : base(propertyName, description, descriptionKey)
        {
        }

        #endregion

        #region Rule Members

        /// <inheritdoc/>
        public override bool ValidateValue(object value)
        {
            return (value is T) && (value != null);
        }

        #endregion
    }
}
